package com.seven.web;

import com.seven.db.Database;
import com.seven.service.SendEMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author seven
 * @Date 2020/5/11 15:44
 **/
@RestController
public class SendController {
    @Autowired
    private SendEMailService sendEMailService;

    //注册
    @GetMapping("register")
    public String register(String name,String email){
        long start = System.currentTimeMillis();
        if (name!=null){
            //发送邮箱
            sendEMailService.send(email,name);
            Database.save(name);
            System.out.println("耗时："+(System.currentTimeMillis()-start)+"ms");
            return "已经给您发送邮件，请登录邮件激活";
        }
        return "register未知错误";
    }
    //模拟登录
    @GetMapping("login")
    public String login(String name){
        if (name!=null){
            //查看是否激活
            if (Database.get(name)) {
                return "登录成功";
            }
            return "登录失败";
        }
        return "login未知错误";
    }
    //激活
    @GetMapping("active")
    public String active(String name){
        if (name!=null){
            //查看是否激活
            if (Database.get(name)) {
                return "激活成功";
            }
            return "激活失败";
        }
        return "active未知错误";
    }
}
